﻿using UniMana.Utils.Controls;
using UniMana.Data;
using System.Windows.Forms;
using UniMana.Utils.Configs;
using System;
using DevExpress.XtraBars;
namespace UniMana.Win.Catalogue
{
    public partial class FrmCategories_SubRoom : DevExpress.XtraEditors.XtraForm
    {
        #region[Khai báo biến toàn cục]
        private DBMain m_Catalogue = new DBMain();
        private DBMain m_Class_Room = new DBMain();
        private bds m_bds = new bds();
        public DevExpress.Utils.WaitDialogForm dlg;
        #endregion
        public FrmCategories_SubRoom()
        {
            InitializeComponent();
            LoadData();
            InitControlEvent();
        }
        public void LoadData()
        {
            m_bds.DataSource = m_Class_Room.m_DCSave.Training_Class_Rooms;
            grcTraining_Class_Room.DataSource = m_bds;
        }
        #region [sự kiện các nút]
        public void InitControlEvent()
        {
            xucBar.btnAddNew_Click += new xucBar.ButtonClickHandler(btnAddNew_Click);
            xucBar.btnDelete_Click += new xucBar.ButtonClickHandler(btnDelete_Click);
            xucBar.btnEdit_Click += new xucBar.ButtonClickHandler(btnEdit_Click);
            xucBar.btnCancel_Click += new xucBar.ButtonClickHandler(btnCancel_Click);
            xucBar.btnSave_Click += new xucBar.ButtonClickHandler(btnSave_Click);
            xucBar.btnRefresh_Click += new xucBar.ButtonClickHandler(btnRefresh_Click);
            xucBar.btnImport_Click += new xucBar.ButtonClickHandler(btnImport_Click);
            xucBar.btnExport_Click += new xucBar.ButtonClickHandler(btnExport_Click);
        }
        private void btnAddNew_Click(object sender, ItemClickEventArgs e)
        {
            m_bds.AddNew();
        }
        private void btnDelete_Click(object sender, ItemClickEventArgs e)
        {
            try
            {
                DialogResult result = new DialogResult();
                result = MessageBox.Show("Bạn Có Chắc Xóa Không", "Thông Báo", MessageBoxButtons.YesNo);
                if (result == DialogResult.Yes)
                {
                    if (grvTraining_Class_Room.SelectedRowsCount > 0)
                    {
                        int[] index = grvTraining_Class_Room.GetSelectedRows();
                        for (int i = index[0]; i < index.Length + index[0]; i++)
                        {
                            Training_Class_RoomInfo sjc = new Training_Class_RoomInfo((int)Convert.ToInt16(
                                grvTraining_Class_Room.GetRowCellValue(i, "Training_Class_RoomKey").ToString()));
                            sjc.Delete();
                        }
                    }
                }
                else
                {
                }
            }
            catch
            {
            }
        }
        private void btnEdit_Click(object sender, ItemClickEventArgs e)
        {

        }
        private void btnCancel_Click(object sender, ItemClickEventArgs e)
        {
            this.Validate(); m_bds.CancelEdit();
        }
        private void btnSave_Click(object sender, ItemClickEventArgs e)
        {
            try
            {
                this.Validate();
                dlg = new DevExpress.Utils.WaitDialogForm(MsgConfig.MSG_WAIT, MsgConfig.MSG_LOADING);
                m_Class_Room.m_DCSave.SubmitChanges();
                dlg.Close();
            }
            catch
            {
            }
        }
        private void btnRefresh_Click(object sender, ItemClickEventArgs e)
        {

        }
        private void btnImport_Click(object sender, ItemClickEventArgs e)
        {

        }
        private void btnExport_Click(object sender, ItemClickEventArgs e)
        {

        }
        #endregion

        private void FrmTraning_Class_Room_FormClosing(object sender, FormClosingEventArgs e)
        {
            Training_Class_RoomInfo dt = new Training_Class_RoomInfo();
            dt.CheckBeforSave();
        }
        #region [Các hàm sử dụng]        
        #endregion
    }
}